package com.yonyou.pmclouds.outter.role;

import java.util.List;
import java.util.Map;

import com.yonyou.pmclouds.basecom.util.YhtSdkProperties;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.yonyou.iuap.tenant.sdk.RoleCenter;
import com.yonyou.pmclouds.basecom.exception.BusinessException;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class RoleInfoQuery {

	private ObjectMapper objectMapper;

	public RoleInfoQuery() {
		objectMapper = new ObjectMapper();
	}
	
	/**
	 * 
	 * 方法功能描述：查询租户下的所有角色。
	 * 
	 * <b>参数说明</b>
	 * @param pk_tenant
	 * @return
	 * @throws BusinessException
	 * @author zhangwce
	 * @time 2018年1月25日 下午11:00:30
	 */
	public List queryRolesByTenant(String pk_tenant) throws BusinessException {
		String roleResult = RoleCenter.queryRoles(YhtSdkProperties.getSysId(), pk_tenant);

		Map roleResultMap = null;
		try {
			roleResultMap = objectMapper.readValue(roleResult, Map.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		if (Integer.valueOf(0).equals(roleResultMap.get("status"))) {
			String roleResultMsg = roleResultMap.get("msg") == null ? "" : (String) roleResultMap.get("msg");
			log.error("查询租户角色出错，具体错误信息为：" + roleResultMsg);
			throw new BusinessException("查询租户角色出错，具体错误信息为：" + roleResultMsg);
		}

		List roleResultList = (List) roleResultMap.get("data");
		return roleResultList;
	}


	
}
